package sing.flutter

import android.os.Bundle
import android.widget.LinearLayout
import com.bytedance.sdk.openadsdk.CSJSplashAd
import com.bytedance.sdk.openadsdk.CSJSplashCloseType
import sing.core.base.BaseActivity
import sing.core.base.BaseViewModel
import sing.myapp.BR
import sing.myapp.R
import sing.myapp.databinding.AdActivityBinding

class AdActivity : BaseActivity<BaseViewModel, AdActivityBinding>(R.layout.ad_activity, BR._all) {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val view = findViewById<LinearLayout>(R.id.parent)
//        var splashAD = SplashAD(this, "广告位id");
//        splashAD.show(view)
        if (!this.isFinishing && FlutterPlugin.ad != null) {
            FlutterPlugin.ad.setSplashAdListener(object : CSJSplashAd.SplashAdListener {
                override fun onSplashAdShow(csjSplashAd: CSJSplashAd) {}
                override fun onSplashAdClick(csjSplashAd: CSJSplashAd) {}
                override fun onSplashAdClose(csjSplashAd: CSJSplashAd, closeType: Int) {
                    if (closeType == CSJSplashCloseType.CLICK_SKIP) {
                    } else if (closeType == CSJSplashCloseType.COUNT_DOWN_OVER) {
                    } else if (closeType == CSJSplashCloseType.CLICK_JUMP) {
                    }
                    finish()
                }
            })
            FlutterPlugin.ad.showSplashView(view)
        } else {
            finish()
        }
    }

    override fun onPause() {
        super.onPause()
        overridePendingTransition(0, 0)
    }
}
